package com.community.process._1010.dao.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.community.process._1010.common.base.BaseEntity;
import com.community.process._1010.common.utils.SystemAmountUtil;
import com.community.process._1010.domains.ProcessIngredientsDTO;
import com.oneadds.lowcode.annotation.JoinColumn;
import com.oneadds.lowcode.annotation.JoinTable;
import com.oneadds.lowcode.constant.JoinConstant;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 到餐加工食材
 *
 * @author Zbs
 * @since 2024-09-05
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@TableName("yg_process_ingredients")
@Schema(description = "到餐加工食材")
public class ProcessIngredients extends BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    @Schema(description = "食材名称")
    private String name;

    @Schema(description = "分类ID")
    private Long categoryId;

    @Schema(description = "最小购买")
    private Integer min;

    @Schema(description = "最大够买")
    private Integer max;

    @Schema(description = "食材图片")
    private String image;

    @Schema(description = "单位数量加工费 单位：分")
    private Long processingFee;

    @Schema(description = "单位数量价格 单位：分")
    private Long price;

    @Schema(description = "单位")
    private String units;

    @Schema(description = "单位数量")
    private Integer unitsNum;

    @Schema(description = "上下架 1 上架 0 下架")
    private Integer up;

    public ProcessIngredients(ProcessIngredientsDTO.IngredientsAdd dto) {
        this.up = 1;
        initBaseParams(dto);
    }

    public ProcessIngredients(ProcessIngredientsDTO.IngredientsUpdate dto) {
        this.setId(dto.getId());
        this.up = dto.getUp();
        initBaseParams(dto);
    }

    private void initBaseParams(ProcessIngredientsDTO.IngredientsBase dto) {
        this.name = dto.getName();
        this.categoryId = dto.getCategoryId();
        this.min = dto.getMin();
        this.max = dto.getMax();
        this.image = dto.getImage();
        this.processingFee = SystemAmountUtil.yuanToPenny(dto.getProcessingFee());
        this.price = SystemAmountUtil.yuanToPenny(dto.getPrice());
        this.units = dto.getUnits();
        this.unitsNum = dto.getUnitsNum();
    }

}
